package com.avecsys.quotemanager.dao.menu;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.avecsys.quotemanager.dao.common.BaseDAOImpl;
import com.avecsys.quotemanager.pojos.menu.RootMenuEntity;

/**
 * @author Samsundar.K
 * 
 */
public class MenuManagerDAOImpl extends BaseDAOImpl implements MenuManagerDAO {
	/**
	 * Get all Menus
	 * 
	 * @return List<RootMenuEntity>
	 */
	@SuppressWarnings("unchecked")
	public List<RootMenuEntity> getAllMenus() {
		return (List<RootMenuEntity>) getHibernateTemplate().executeFind(
				new HibernateCallback<List<RootMenuEntity>>() {
					public List<RootMenuEntity> doInHibernate(Session session)
							throws HibernateException, SQLException {
						Criteria criteria = session
								.createCriteria(RootMenuEntity.class);
						criteria.addOrder(Order.asc("rootMenuOrder"));
						List<RootMenuEntity> rootMenuEntityList = criteria
								.list();
						return rootMenuEntityList;
					}
				});
	}
}
